from matplotlib import rc
rc('font',**{'family':'serif','serif':['Times']})
rc('text', usetex=True)

import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
import matplotlib.pyplot as pyplot
x1, y1, den1, den2, den3, den4 = np.loadtxt('fig6a_6d.dat', unpack=True)

x2, y2, phi1, phi2, phi3, phi4 = np.loadtxt('fig6e_6h.dat', unpack=True)

#X3, y3, den3 = np.loadtxt('fig6c.dat', unpack=True)
 
#X4, y4, den4 = np.loadtxt('fig6d.dat', unpack=True)

#X1, y1, phi1 = np.loadtxt('fig6e.dat', unpack=True)

#X2, y2, phi2 = np.loadtxt('fig6f.dat', unpack=True)

#X3, y3, phi3 = np.loadtxt('fig6g.dat', unpack=True)

#X4, y4, phi4 = np.loadtxt('fig6h.dat', unpack=True)

#Calculating the dimension of the matrix
#
Nphi1  = int(len(phi1)**.5)
#
Nphi2  = int(len(phi2)**.5)
#
Nphi3  = int(len(phi3)**.5)
#
Nphi4  = int(len(phi4)**.5)

#
Nden1  = int(len(den1)**.5)
#
Nden2  = int(len(den2)**.5)
#
Nden3  = int(len(den3)**.5)
#
Nden4  = int(len(den4)**.5)


########
#
phi1  = phi1.reshape(Nphi1, Nphi1)
phi1  = np.rot90(phi1)
#   
########
phi2  = phi2.reshape(Nphi2, Nphi2)
phi2  = np.rot90(phi2)
########
phi3  = phi3.reshape(Nphi3, Nphi3)
phi3  = np.rot90(phi3)
########
phi4  = phi4.reshape(Nphi4, Nphi4)
phi4  = np.rot90(phi4)
########

den1  = den1.reshape(Nden1, Nden1)
den1  = np.rot90(den1)
#   
########
den2  = den2.reshape(Nden2, Nden2)
den2  = np.rot90(den2)
########
den3  = den3.reshape(Nden3, Nden3)
den3  = np.rot90(den3)
########
den4  = den4.reshape(Nden4, Nden4)
den4  = np.rot90(den4)
########

cm = plt.cm.get_cmap('gnuplot2')#.reversed()

#############################################################################
## Positioning of subplots, and specifying the number of rows and columns ###
## in the resulting multiplot                                             ###
#############################################################################
fig1 = plt.figure(1)
fig1, axes = plt.subplots(nrows=2, ncols=4, figsize=(15, 7.5))
plt.subplots_adjust(left=0.08, bottom=0.1, right=0.90, top=0.98,
                        wspace=0.07, hspace=0.01)
rc('axes', linewidth=1)
fontsize = 26
########################################
####   Figure (a)       ################
########################################
plt.subplot(2,4,1)
ax = plt.gca()
ax.text(43, 45.6,'(a)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})

plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.yticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)

plt.imshow(den1, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=2,cmap=cm, interpolation='none')

########################################
####   Figure (b)       ################
########################################
plt.subplot(2,4,2)
ax = plt.gca()
ax.text(43, 45.6,'(b)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)

plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den2, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
          vmin=0, vmax=2, cmap=cm, interpolation='none')

########################################
####   Figure (c)       ################
########################################
plt.subplot(2,4,3)
ax = plt.gca()
ax.text(43, 45.6,'(c)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den3, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=2,cmap=cm, interpolation='none')

########################################
####   Figure (d)       ################
########################################
plt.subplot(2,4,4)
ax = plt.gca()
ax.text(43, 45.6,'(d)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(den4, extent=(np.amin(x1), np.amax(x1), np.amin(y1), np.amax(y1)),\
            vmin=0, vmax=2,cmap=cm, interpolation='none')

cbaxes = fig1.add_axes([0.93, 0.56, 0.02, 0.4])
cb = plt.colorbar(cax = cbaxes)
cb.ax.tick_params(labelsize=26)
cb.set_ticks([0,1,2])
cb.set_ticklabels(['0','1','2'])

########################################
####   Figure (e)       ################
########################################
plt.subplot(2,4,5)
ax = plt.gca()

ax.text(43, 45.6,'(e)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.yticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)

plt.imshow(phi1, extent=(np.amin(x2), np.amax(x2), np.amin(y2), np.amax(y2)),\
            vmin=0, vmax=0.5,cmap=cm, interpolation='none')

########################################
####   Figure (f)       ################
########################################
plt.subplot(2,4,6)
ax = plt.gca()
ax.text(43, 45.6,'(f)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)

plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(phi2, extent=(np.amin(x2), np.amax(x2), np.amin(y2), np.amax(y2)),\
          vmin=0, vmax=0.5, cmap=cm, interpolation='none')

########################################
####   Figure (g)       ################
########################################
plt.subplot(2,4,7)
ax = plt.gca()
ax.text(43, 45.6,'(g)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})
plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)
plt.imshow(phi3, extent=(np.amin(x2), np.amax(x2), np.amin(y2), np.amax(y2)),\
            vmin=0, vmax=0.5,cmap=cm, interpolation='none')

########################################
####   Figure (h)       ################
########################################
plt.subplot(2,4,8)
ax = plt.gca()
ax.text(43, 45.6,'(h)', fontsize=26, color='red', bbox={'facecolor':'white','alpha':0.9,'pad':2})

plt.minorticks_on()
plt.xlim(-0.5, 49.5)
plt.ylim(-0.5, 49.5)
plt.xticks([-0.5,19.5,39.5],['$0$','$20$','$40$'],fontsize=26)
plt.yticks([-0.5,19.5,39.5],['','',''],fontsize=26)

plt.imshow(phi4, extent=(np.amin(x2), np.amax(x2), np.amin(y2), np.amax(y2)),\
            vmin=0, vmax=0.5,cmap=cm, interpolation='none')
#
########################################
########################################
#Set Color bar
cbaxes = fig1.add_axes([0.93, 0.12, 0.02, 0.4])
cb = plt.colorbar(cax = cbaxes)
cb.ax.tick_params(labelsize=26)
cb.set_ticks([0,0.25,0.5])
cb.set_ticklabels(['0.0','','0.5'])

fig1.text(0.47, 0.03, r'$x$ (in units of $a$)',fontsize=26, ha='center', va='center')

fig1.text(0.025, 0.55, r'$y$ (in units of $a$)',fontsize=26, ha='center', va='center', rotation='vertical')


plt.show()
fig1.savefig('den_phi_plots.pdf')

